package com.kehao.leetcode.basic.sortAndSearch;



public class SortAndSearchSolution2 {

    boolean isBadVersion(int version){
        return true;
    }


    public int firstBadVersion(int n) {
//        return firstBadVersion(1,n);
        int startVersion=0;
        int lastVersion=n;
        while (startVersion<lastVersion){
            int midVersion = startVersion+(lastVersion-startVersion)/2;
            if(isBadVersion(midVersion)){
                lastVersion=midVersion;
            }else {
                startVersion=midVersion+1;
            }
        }
        return startVersion;
    }


    public int firstBadVersion(int startVersion,int lastVersion) {
        int midVersion = startVersion+(lastVersion-startVersion)/2;;
        if(startVersion == lastVersion){
            return startVersion;
        }else if(isBadVersion(midVersion)){
            return firstBadVersion(startVersion,midVersion);
        }else {
            return firstBadVersion(midVersion+1,lastVersion);
        }
    }

}
